//
//  MyCenterViewController.m
//  RedHareCar
//
//  Created by WDL on 16/12/20.
//  Copyright © 2016年 CarCredit. All rights reserved.
//

#import "MyCenterViewController.h"

/** 我的收藏*/
#import "CollectTableViewController.h"
/** 我的分期*/
#import "StagingTableViewController.h"
/** 意见反馈*/
#import "OpinionViewController.h"
/** 设置*/
#import "SettingTableViewController.h"

#define HeadImgHeight 195

@interface MyCenterViewController ()

@end

@implementation MyCenterViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    
}
/**
 *  重写这个代理方法就行了，利用contentOffset这个属性改变frame
 */
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGFloat offsetY = scrollView.contentOffset.y;
    
    if (offsetY < 0) {
        self.headerimageView.frame = CGRectMake(offsetY/2, offsetY, Screen_Width - offsetY, HeadImgHeight - offsetY);  // 修改头部的frame值就行了
    }
    /* 往上滑动contentOffset值为正，大多数都是监听这个值来做一些事 */
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
    
        if (indexPath.row == 0) {
            /** 我的收藏*/
            CollectTableViewController *collect = [[CollectTableViewController alloc]init];
            [self.navigationController pushViewController:collect animated:YES];
            
        }else if (indexPath.row == 1)
        {
            /** 我的分期*/
            StagingTableViewController *stagingCtl = [[StagingTableViewController alloc]init];
            [self.navigationController pushViewController:stagingCtl animated:YES];
            
            
        }
    }else if (indexPath.section == 1)
    {
        if (indexPath.row == 0)
        {
            /** 联系客服*/
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"拨打电话" message:@"010-400-888-888"  preferredStyle:UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                NSLog(@"下次再说--do nothing");
                
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                NSLog(@"拨打电话");
                NSString *telUrl  = [NSString stringWithFormat:@"tel://%@",@"010-400888888"];
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telUrl]];
            }]];
            [self presentViewController:alert animated:YES completion:^{
            }];
            
            
        }else if (indexPath.row == 1)
        {
            /** 意见反馈*/
            /** 加载 StoryBoard */
            OpinionViewController * OpinionCtl = [[OpinionViewController alloc]init];
            UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:@"MyCenter" bundle:nil];
            OpinionCtl = [storyBoard instantiateViewControllerWithIdentifier:@"OpinionViewController"];
            [self.navigationController pushViewController:OpinionCtl  animated:YES];
            
            
        }
    }else if (indexPath.section == 2)
    {
        if (indexPath.row == 0)
        {
            /** 分享好友*/
            
            
            
        }else if (indexPath.row == 1)
        {
            /** 设置*/
            /** 加载 StoryBoard */
            SettingTableViewController * SettingCtl = [[SettingTableViewController alloc]init];
            UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:@"MyCenter" bundle:nil];
            SettingCtl = [storyBoard instantiateViewControllerWithIdentifier:@"SettingTableViewController"];
            [self.navigationController pushViewController:SettingCtl animated:YES];
            
            
        }
        
        
    }
    
}


@end
